package com.example.card.implemention;

import com.example.card.domain.card.CardClassification;

import java.time.LocalDate;

public class RedCardClassification extends CardClassification {

    private final OilValue oilValue;

    private LimitConsumptionDate limitConsumptionDate;

    public RedCardClassification(OilValue oilValue) {
        this.oilValue = oilValue;
        limitConsumptionDate =reset();
    }

    @Override
    public int calculate(PayCheck pc) {
        checkLimit(pc.getAmount());

        return 0;
    }

    LimitConsumptionDate reset() {
        LocalDate now = LocalDate.now();
        return new LimitConsumptionDate(now, now, 1000_00);
    }

    private void checkLimit(Integer amount) {
        if (!limitConsumptionDate.inPeriod()) {
            reset();
        }
        if (limitConsumptionDate.outLimit(amount)) {
            throw new RuntimeException("改卡超出当日限额");
        }
    }


    public OilValue getOilValue() {
        return oilValue;
    }
}
